/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.dao.product;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.neusoft.lohas.common.persistence.BaseDao;
import com.neusoft.lohas.common.persistence.Parameter;
import com.neusoft.lohas.modules.ivm.entity.product.Product;

/**
 * 商品信息DAO接口
 * @author Jackie.Liu
 * @version 2014-11-13
 */
@Repository
public class ProductDao extends BaseDao<Product> {
	
	public Product findByName(String merchantId, String name){
		return getByHql("from Product where merchant.id = :p1 and name = :p2 and delFlag = :p3", new Parameter(merchantId, name, Product.DEL_FLAG_NORMAL));
	}
	
	/**
	 * 获取该商户的最大商品编号
	 * @param merchantId
	 * @return
	 */
	public long getMaxCode(String merchantId){
		String sql = "select ifnull(max(code), 999) as maxCode from ivm_product where merchant_id=:p1";
		List<Map<String, Object>> list = findBySql(sql, new Parameter(merchantId), Map.class);
		long maxCode = Long.valueOf(list.get(0).get("maxCode").toString());
		return maxCode;
	}

	/**
	 * 更新浏览次数
	 * @param id
	 */
	public void updateScanNum(String id) {
		update("update Product set scan=scan+:p1 where id = :p2", new Parameter(1,id));
	}
}
